﻿<?php


class ContentApp extends BaseApp
{

    var $type = NULL;
    var $table_id = 0;	
	var $view_scup_dir = '';

	function __construct() 
	{
      $this->ContentApp();
	}
		
	function ContentApp() 
	{
	   $this->view_scup_dir = ROOT_PATH.'/scup/view/'.VIEW_TYPE; 
	   $this->table_id = $GLOBALS['SCup']->SCup_module_table_id;
	   $this->type = $GLOBALS['SCup']->SCup_module_appname;	      
	   parent::__construct();
	}	
	
    function index()
    {

        if(!isset($_GET['catid']))
		{
		$_GET['catid'] = '';
		}	
        if(!isset($_GET['condition']))
		{
		$_GET['condition'] = '';
		}
		$condition = $_GET['condition'];						
		$catid = intval($_GET['catid']);	
        if(!isset($_GET['word']))
		{
		$_GET['word'] = '';
		}					
        if(!isset($_POST['word']))
		{
		$_POST['word'] = '';
		}
		
        if(!isset($_GET['v']))
		{
		$_GET['v'] = '';
		}
		if($_GET['word'])
		{
	    $word = $_GET['word'];		
		}
		if($_POST['word'])
		{
	    $word = $_POST['word'];		
		}		

		$word_array = explode(' ',$word);
		
		foreach($word_array as $key => $value)
		{
			if(!$value)
			{
             unset($word_array[$key]);
		    }  
		}
		 
        $order = '';
		$v = $_GET['v'];
		if($v == 'timeasc')
		{
        $order = 'add_time asc';
		}
		else if($v == 'timedesc')
		{
        $order = 'add_time desc';		
		}
		else if($v == 'showyes')
		{
        $order = 'is_show desc';		
		}
		else if($v == 'showno')
		{
        $order = 'is_show asc';		
		}
		else if($v == 'topyes')
		{
        $order = 'is_top desc';		
		}
		else if($v == 'topno')
		{
        $order = 'is_top asc';		
		}
		else if($v == 'recyes')
		{
        $order = 'is_recommend desc';		
		}
		else if($v == 'recno')
		{
        $order = 'is_recommend asc';		
		}
		else if($v == 'indexyes')
		{
        $order = 'is_index desc';		
		}
		else if($v == 'indexno')
		{
        $order = 'is_index asc';		
		}

        $temp_condition = $condition;		
        if($condition == 'showyes')
		{
        $condition = 'is_show=1';		
		}
		else if($condition == 'showno')
		{
        $condition = 'is_show=0';		
		}
		else if($condition == 'topyes')
		{
        $condition = 'is_top=1';		
		}
		else if($condition == 'topno')
		{
        $condition = 'is_top=0';		
		}
		else if($condition == 'recyes')
		{
        $condition = 'is_recommend=1';		
		}
		else if($condition == 'recno')
		{
        $condition = 'is_recommend=0';		
		}
		else if($condition == 'indexyes')
		{
        $condition = 'is_index=1';		
		}
		else if($condition == 'indexno')
		{
        $condition = 'is_index=0';		
		}		
		
		
        $module_list_data = & get_module_list_data();
        $this->assign('modulename', $module_list_data[$GLOBALS['SCup']->SCup_module_appname]['alias']);	
			
		$TB_new = &$this->_model('content');
	
		$data = $TB_new->show($order,$v,$word_array,$this->table_id,$this->type,$catid,$condition,$word,$temp_condition);	
		
        $this->assign('lw_data', $data['data']);		
		$this->assign('lw_page', $data['page']);	
		
	 	$categorydata =  $GLOBALS['SCup']->_get_category_data($this->type);

		$categorylist = array();
		if(empty($categorydata))$categorydata = array();
		foreach((array)$categorydata as $key =>$value)
		{
		    $categorylist[$value['cat_id']] = $value['cat_name'];
		}		
        $this->assign('categorydata', $categorydata);	
		
        $this->assign('categorylist', $categorylist);							
        $this->assign('appname', $this->type);	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	

		$this->assign('word', $word);
		$this->assign('v', $v);
		$this->assign('condition', $temp_condition);		
		$this->assign('catid', $catid);
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display("content_{$this->table_id}_list.view.html");
    }

    function add()
    {
		
        $module_list_data = & get_module_list_data();
        $this->assign('modulename', $module_list_data[$GLOBALS['SCup']->SCup_module_appname]['alias']);		
		$TB_new = &$this->_model('content'); 
		 	
		$id_array = $TB_new->select_id($this->table_id,$GLOBALS['SCup']->SCup_user_msg['user_id']);		
		foreach($id_array as $value)
		{
		   if($value['id']&&file_exists(ROOT_PATH . '/' . UPFILE_PATH . '/' . $this->type . '/' . $value['id'] . '/'))
		   {		
		      del_file(ROOT_PATH . '/' . UPFILE_PATH . '/' . $this->type . '/' . $value['id'] . '/');
		   }	
		}		
		$TB_new->delet_id($this->table_id,$GLOBALS['SCup']->SCup_user_msg['user_id']);	
		$data_id = $TB_new->insert_id($this->table_id,$GLOBALS['SCup']->SCup_user_msg['user_id']);

		$data = array();
		$data['id'] = $data_id;
        $this->assign('data', $data);	
        $this->assign('id', $data_id);
				
        $this->assign('keyworddata', del_empty_var(explode('+', AWAY_USE_KEYWORD)));	
        $this->assign('zhandian', del_empty_var(explode('+', AWAY_USE_ZHANDIAN)));		
	 	$categorydata = & $GLOBALS['SCup']->_get_category_data($this->type);
		   
        $this->assign('categorydata', $categorydata);		
        $this->assign('appname', $this->type);		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display("content_{$this->table_id}_add.view.html");
    }
	
    function kindeditor()
    {
    $w = intval($_GET['w']);
    include(ROOT_PATH."/data/ewebeditor/ewebeditor.lib.php");	
	$kindeditor = new Ewebeditor(array('imageUploadCgi'=>SITE_URL.'/admin/index.php?app='.$this->type.'&act=kindeditorupfile&w='.$w));
	$kindeditor->show();
	
    }
	
    function kindeditorupfile()
    {
    $w = intval($_GET['w']);
    include(ROOT_PATH."/data/ewebeditor/ewebeditor.lib.php");	
	$kindeditor = new Ewebeditor(array('imageUploadCgi'=>SITE_URL.'/admin/index.php?app='.$this->type.'&act=kindeditorupfile&w='.$w));
	$kindeditor->upfile($this->type.'/'.$w);	
    }
	
	

    function cagryadd()
    {
        $module_list_data = & get_module_list_data();
        $this->assign('modulename', $module_list_data[$GLOBALS['SCup']->SCup_module_appname]['alias']);	
	    $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		$catgydata = $category->show($this->type);
		
		$catgystr = $category->html_format_category($catgydata,0);	

        $this->assign('catgystr', $catgystr);	
		
        $this->assign('appname', $this->type);

        $this->assign('viewdata', $this->get_view_data());
		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('cagryadd.view.php');
    }
	
    function editcatgy()
    {
	
        $module_list_data = & get_module_list_data();
        $this->assign('modulename', $module_list_data[$GLOBALS['SCup']->SCup_module_appname]['alias']);	
		
		$id= intval($_GET['id']);
		
	    $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		$catgydata = $category->show($this->type);
		
		$data = $category->oneshow($id);
		

		$catgystr = $category->html_format_category($catgydata,$data['parent_id'],0,0,$id);		

/*
	    if(is_file($this->view_scup_dir."/contentshow_{$appid}_{$id}.view.html"))
		{
		$view_file_show = $this->view_scup_dir."/contentshow_{$appid}_{$id}.view.html";		
	    }else
		{
		$view_file_show = $this->view_scup_dir."/content/{$data[viewshowname]}";
	    }
	    $view_scup_show=str_replace(array("<",">"),array("&lt;","&gt;"),read_file($view_file_show));
        $this->assign('view_file_show', $view_file_show);		
        $this->assign('view_scup_show', $view_scup_show);

	    if(is_file($this->view_scup_dir."/content_{$this->table_id}_{$id}.view.html"))
		{
		$view_file_index = $this->view_scup_dir."/content_{$this->table_id}_{$id}.view.html";		
	    }else
		{
		$view_file_index = $this->view_scup_dir."/content/{$data[viewname]}";
	    }		
	    $view_scup_index=str_replace(array("<",">"),array("&lt;","&gt;"),read_file($view_file_index));
        $this->assign('view_file_index', $view_file_index);		
        $this->assign('view_scup_index', $view_scup_index);	
*/
        $this->assign('data', $data);
        $this->assign('catgystr', $catgystr);
        $this->assign('viewdata', $this->get_view_data());		
        $this->assign('appname', $this->type);
			    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('cagryedit.view.php');
    }
	
    function cagrylist()
    {

        $module_list_data = & get_module_list_data();
        $this->assign('modulename', $module_list_data[$GLOBALS['SCup']->SCup_module_appname]['alias']);		
	    $category = & $GLOBALS['SCup']->_get_category();
		$catgydata = $category->show($this->type);
		$catgydata = $category->get_list_category($catgydata);
        $this->assign('catgydata', $catgydata);				
        $this->assign('appname', $this->type);
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
        $this->assign('site_url',SITE_URL);
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
        $this->display('cagrylist.view.php');
    }

    function cyaddpost()
    {

	     $data = $_POST['data'];
		include(ROOT_PATH."/lib/pinyin.lib.php"); 
		$p = new pingyin();
        if (isset($data['pinyin'])&&!empty($data['pinyin'])) {
            $data['pinyin'] = $p->Pinyin($data['pinyin'],1);
        }
		if (empty($data['pinyin'])) {
            $data['pinyin'] = $p->Pinyin($data['cat_name'],1);
        } 
		 if(empty($data['viewname']))
		 {
		 $data['viewname'] = 'content.view.html';
		 }

		 if(empty($data['viewshowname']))
		 {
		 $data['viewshowname'] = 'contentshow.view.html';
		 }
		 $category = & $GLOBALS['SCup']->_get_category();
		 		 		
		 $category->post($data);
		 $id = get_db()->insert_id();

		 $category->write_cache($this->type);
		 $this->write_module_default_scupshow_html($id,$data['viewshowname']);		 
		 $this->write_module_default_scup_html($id,$data['viewname']);		 	 		 
		 $this->cagrylist();

    }


    function cyeditpost()
    {
         if(!isset($_POST['id']))
		 {
		   $_POST['id']='';
		 }
         if(!isset($_POST['data']))
		 {
		   $_POST['data']='';
		 }		 
         if(!isset($_POST['scupindex']))
		 {
		   $_POST['scupindex']='';
		 }
         if(!isset($_POST['scupshow']))
		 {
		   $_POST['scupshow']='';
		 }		 		 
	     $id = $_POST['id'];
	     $data = $_POST['data'];
		include(ROOT_PATH."/lib/pinyin.lib.php"); 
		$p = new pingyin();
        if (isset($data['pinyin'])&&!empty($data['pinyin'])) {
            $data['pinyin'] = $p->Pinyin($data['pinyin'],1);
        }
		if (empty($data['pinyin'])) {
            $data['pinyin'] = $p->Pinyin($data['cat_name'],1);
        } 		 
         $scupindexdata = $_POST['scupindex'];	
         $scupshowdata = $_POST['scupshow'];
		 if(empty($data['viewname']))
		 {
		 $data['viewname'] = 'content.view.html';
		 }	
		 
		 if(empty($data['viewshowname']))
		 {
		 $data['viewshowname'] = 'contentshow.view.html';
		 }
	     $category = & $GLOBALS['SCup']->_get_category();
	
		 $temp_data = $category->oneshow($id);
         if($temp_data['viewname'] != $data['viewname'])
		 {
		 $this->write_module_default_scup_html($id,$data['viewname']);		 
		 }
		 else
		{
		    if(!empty($scupindexdata))
			{
	             $view_scup_index = stripslashes($scupindexdata);		
     	         write_file( $this->view_scup_dir."/content_{$this->table_id}_{$id}.view.html",$view_scup_index);				
   	            if(!is_writable($this->view_scup_dir."/content_{$this->table_id}_{$id}.view.html"))
		        {	
		        $notice = &get_message(array('msg'=>$this->view_scup_dir."/content_{$this->table_id}_{$id}.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		        $notice ->display();		
	            }			
			}
		 
		 }

         if($temp_data['viewshowname'] != $data['viewshowname'])
		 {
		 $this->write_module_default_scupshow_html($id,$data['viewshowname']);		 
		 }
		 else
		{
		    if(!empty($scupshowdata))
			{
	             $view_scup_show = stripslashes($scupshowdata);		
     	         write_file( $this->view_scup_dir."/contentshow_{$this->table_id}_{$id}.view.html",$view_scup_show);				
   	            if(!is_writable($this->view_scup_dir."/contentshow_{$this->table_id}_{$id}.view.html"))
		        {	
		        $notice = &get_message(array('msg'=>$this->view_scup_dir."/contentshow_{$this->table_id}_{$id}.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		        $notice ->display();		
	            }			
			}
		 
		 }
						
		 $category->editaction($id,$data);

		 $category->write_cache($this->type);	
		 	 		 
		 $this->cagrylist();

    }

	
    function addpost()
    {


	     $data = $_POST['data'];
		 $id = $_POST['id'];

         if(!isset($data['cat_id'])||empty($data['cat_id']))
		{
		 $notice = &get_message(array('msg'=>"所属栏目不能为空!",'url'=>'','title'=>'Notice'));
		 $notice ->display();		 
		 }

		 $data['user_id'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
		 $data['user_name'] = $GLOBALS['SCup']->SCup_user_msg['data']['user_name'];	
		 if(!isset($data['titlecolor']))
		 {
		   $data['titlecolor']='';
		 }
		 if(!isset($data['fonttype']))
		 {
		   $data['fonttype']='';
		 } 
		 $data['config'] = serialize(array('titlecolor'=>$data['titlecolor'],'fonttype'=>$data['fonttype'])); 
		 unset($data['titlecolor'],$data['fonttype']); 
		 if(empty($data['yz']))
		 {
		    $data['yz']='0';
		 }  
		 if(empty($data['top']))
		 {
		    $data['top']='0';
		 }  
		 if(empty($data['levels']))
		 {
		    $data['levels']='0';
		 }  
		 if(empty($data['special']))
		 {
		    $data['special']='0';
		 } 
		 $TB_content = &$this->_model('content');
		 		 		 		
		 $TB_content->editaction($id,$data,$this->table_id);
		 
		$view = &get_view();
	    $view->html($id,SITE_URL ."/?app={$this->type}&act=show&id=$id",$this->type);
		
		 $this->index();

    }

    function upfile()
    {
	 if(!isset($_POST["action"]))
	 {
	 $_POST["action"]='';
	 }
	 if(!isset($_GET['id']))
	 {
	 $_GET['id']='';
	 }
	 if(!isset($_GET["edit"]))
	 {
	 $_GET["edit"]='';
	 }	 
	 if(!isset($_GET["picurl"]))
	 {
	 $_GET["picurl"]='';
	 }	
	 if(!isset($_GET['jsfun']))
	 {
	 $_GET['jsfun']='';
	 }		 
	 if(!isset($_GET['putid']))
	 {
	 $_GET['putid']='';
	 }		 
	 if(!isset($_GET['uppic']))
	 {
	 $_GET['uppic']='';
	 }	
		$tf = $_GET['tf'];
        if(empty($tf))$tf = $_POST['tf'];	 	 	
		$action = $_POST["action"];		
		$id = intval($_GET['id']);		
		$jsfun = $_GET['jsfun'];
		$uppic = $_GET['putid'];
		if(!empty($_GET['uppic']))
		{
		$uppic = $_GET['uppic'];		
		}	
		$edit = $_GET["edit"];
		$picurl = $_GET["picurl"];

        $this->assign('jsfun', $jsfun);		


        $this->assign('uppic', $uppic);		
	
				

        $this->assign('edit', $edit);		


        $this->assign('picurl', $picurl);

        $this->assign('tf', $tf);
						
		if($action == 'post')
		{
			 if(!isset($_POST['jsfun']))
	 {
	 $_POST['jsfun']='';
	 }	
	 if(!isset($_POST['uppic']))
	 {
	 $_POST['uppic']='';
	 }		 
	 if(!isset($_POST["edit"]))
	 {
	 $_POST["edit"]='';
	 }		 
	 if(!isset($_POST["picurl"]))
	 {
	 $_POST["picurl"]='';
	 }	
	 if(!isset($_POST['id']))
	 {
	 $_POST['id']='';
	 }		 
		       $jsfun = $_POST['jsfun'];
		       $uppic = $_POST['uppic'];		
		       $edit = $_POST["edit"];
		       $picurl = $_POST["picurl"];
		 	   $id || $id = intval($_POST['id']);		
		       $filedname = trim(str_replace(array("UP_"),array(""),$uppic)); 
       
		       include(ROOT_PATH.'/lib/upfile.lib.php');	  
	           $upfile = new Upfile($this->type.'/'.$id); 	  
	           $updata = $upfile->_batch_upfile($this->type);		 
		 		 
		       $newfile = $updata[1]['path'];
	       
			   if($edit=='editp' && $picurl)
			   {

			          $TB_new = &$this->_model('content');			    		 		 		
		              $TB_new->editpicurl($id,array("$filedname"=>$newfile),$this->table_id);
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
			          if(!is_dir($pic_dir)&&file_exists($pic_dir))
		              {
		                del_file($pic_dir);	
		              }					  
				   
			   }

			    if($edit=='edit' && $picurl)
		       {
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
			          if(!is_dir($pic_dir)&&file_exists($pic_dir))
		              {
		                del_file($pic_dir);	
		              }				 
		       }
		
		      $pic_url = SITE_URL . '/' . UPFILE_PATH . '/' .$newfile;

              if($tf=='pic')
			  {
	           echo "<img src='{$pic_url}' id='upsrc' width='100px' height='100px'><br/><A HREF='?app=$this->type&act=upfile&edit=$edit&tf=$tf&picurl=$newfile&id=$id&jsfun=$jsfun&uppic=$uppic'>修改图片</A>";			  
			  }else
			  {
	           echo "<A HREF='?app=$this->type&act=upfile&edit=$edit&tf=$tf&picurl=$newfile&id=$id&jsfun=$jsfun&uppic=$uppic'>修改文件</A>";			  
			  }

	    echo "<script>
				if(self==top){
					window.opener.$jsfun('$newfile','$uppic');
					window.self.close();
				}else{
					window.parent.$jsfun('$newfile','$uppic');
				}
		     </script>";
				
	    exit;		
		
		}

        $this->assign('id', $id);
	    $this->assign('app', $this->type);		    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('upfile.view.php');
    }




    function pupfile()
    {	
	 if(!isset($_GET["action"]))
	 {
	 $_GET["action"]='';
	 }
	 if(!isset($_POST["action"]))
	 {
	 $_POST["action"]='';
	 }
	 if(!isset($_GET['id']))
	 {
	 $_GET['id']='';
	 }
	        if(!isset($_POST['id']))
	        {
	          $_POST['id']='';
	        }  	
		$action = $_GET["action"];			
		$action || $action = $_POST["action"];
		
		$id = intval($_GET['id']);
		$cid =$id;
		$tf = $_GET['tf'];
        if(empty($tf))$tf = $_POST['tf'];	
						
		if($action == 'post')
		{
		
		 	   $id || $id = intval($_POST['id']);		
               $cid = $id;
		       include(ROOT_PATH.'/lib/upfile.lib.php');	  
	           $upfile = new Upfile($this->type.'/'.$id); 	  
	           $updata = $upfile->_batch_upfile($this->type);		 
		 		 
		       $newfile = $updata[1]['path'];
			   
               unset($data);
		       $data['uid'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];		       
               $data['con_id'] = $id;
               $data['appname'] = $this->type;			   
			   $data['file_url'] = $updata[1]['path'];
			   $data['size'] = $updata[1]['size'];
			   $data['type'] = $updata[1]['type'];
			   			   
			   $TB_new = &$this->_model('upfile');			    		 		 		
		       $TB_new->post($data);
					   	   
	    }
		else if($action == 'del')
		{
			   $id || $id = intval($_POST['id']);   
			   $TB_new = &$this->_model('upfile');
			   
			    $picdata = $TB_new->oneshow($id);
				$picurl = $picdata['file_url'];
                $cid = $picdata['con_id'];
			   			    		 		 		
		       $TB_new->del($id);
					  
		       $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
			   if(!is_dir($pic_dir)&&file_exists($pic_dir))
		       {
		           del_file($pic_dir);	
		       }				
		
		}			

	    $TB_new = &$this->_model('upfile');

        $this->assign('picdata', $TB_new ->selct($cid,$this->type));		
        $this->assign('tf', $tf);	
        $this->assign('id', $cid);
	    $this->assign('app', $this->type);					    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('pupfile.view.php');
    }



    function edit()
    {
        $module_list_data = & get_module_list_data();
        $this->assign('modulename', $module_list_data[$GLOBALS['SCup']->SCup_module_appname]['alias']);		
	
		$id= intval($_GET['id']);
		
		$TB_new = &$this->_model('content');
				
		$data = $TB_new->oneshow($id,$this->table_id);
		
        $this->assign('keyworddata', del_empty_var(explode('+', AWAY_USE_KEYWORD)));
        $this->assign('zhandian', del_empty_var(explode('+', AWAY_USE_ZHANDIAN)));

	 	$categorydata = & $GLOBALS['SCup']->_get_category_data($this->type);
        $this->assign('edit', 'editp');			
        $this->assign('categorydata', $categorydata);

        $this->assign('data', $data);
        $this->assign('appname', $this->type);	
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display("content_{$this->table_id}_edit.view.html");     

    }

    function editpost()
    {
		 $id= intval($_POST['id']);
		
		 $data = $_POST['data'];
         if(!isset($data['cat_id'])||empty($data['cat_id']))
		{
		 $notice = &get_message(array('msg'=>"所属栏目不能为空!",'url'=>'','title'=>'Notice'));
		 $notice ->display();		 
		 }
	
		 $data['user_id'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];
		 $data['user_name'] = $GLOBALS['SCup']->SCup_user_msg['data']['user_name'];	 
		 if(!isset($data['titlecolor']))
		 {
		   $data['titlecolor']='';
		 }
		 if(!isset($data['fonttype']))
		 {
		   $data['fonttype']='';
		 } 		 
		 
		 $data['config'] = serialize(array('titlecolor'=>$data['titlecolor'],'fonttype'=>$data['fonttype']));
		 		 unset($data['titlecolor'],$data['fonttype']); 
		 if(empty($data['yz']))
		 {
		    $data['yz']='0';
		 }  
		 if(empty($data['top']))
		 {
		    $data['top']='0';
		 }  
		 if(empty($data['levels']))
		 {
		    $data['levels']='0';
		 }  
		 if(empty($data['special']))
		 {
		    $data['special']='0';
		 } 		  
 		$TB_content = &$this->_model('content');  
				
		$TB_content->editaction($id,$data,$this->table_id);
		$view = &get_view();
	    $view->html($id,SITE_URL ."/?app={$this->type}&act=show&id=$id",$this->type);	
		
		$this->index();  	      

    }

    function batch()
    {  
	    if(!isset($_POST['jobs'])){$_POST['jobs']=0;}

	    if(!isset($_GET['selcetid'])){$_GET['selcetid']=0;}	
	    if(!isset($_POST['checkdata'])){$_POST['checkdata']=array();}
        if(empty($_POST['checkdata']))
		{
		    $notice = &get_message(array('msg'=>"请至少选择一个项目！",'url'=>'?app='.$this->type.'&act=index','title'=>'Notice'));
		    $notice ->display();				 
		}
		$checkdata = $_POST['checkdata'];		

	    $str='';
		foreach($checkdata as $key => $value)
		{
			  $str.="id='".$value."'  or ";

		}			
		$str = substr($str, 0,-3);
		$db = & get_db();						 						
		$jobs = $_POST['jobs'];
		
        if($jobs=='html')
		{
		
		    $view = &get_view();
		    foreach($checkdata as $key => $value)
		    {
	        $view->html($value,SITE_URL ."/?app={$this->type}&act=show&id=$value",$this->type);	
		    }
		
		$notice = &get_message(array('msg'=>"操作成功！",'url'=>'?app='.$this->type.'&act=index','title'=>'Notice'));
		$notice ->display();		 
		}		
        if($jobs=='move')
		{
		$selcetid = intval($_GET['selcetid']);
		$db->query("UPDATE ".DB_PREFIX."content_".$this->table_id." SET cat_id='{$selcetid}' WHERE ".$str." ");
		$notice = &get_message(array('msg'=>"操作成功！",'url'=>'?app='.$this->type.'&act=index','title'=>'Notice'));
		$notice ->display();		 
		}
        if($jobs)
		 {            
			$jobdata = del_empty_var(explode(':', $jobs));	
			$filed_key = $jobdata[0];
			$filed_value = $jobdata[1];		 
			$db->query("UPDATE ".DB_PREFIX."content_".$this->table_id." SET {$filed_key}='{$filed_value}' WHERE ".$str." ");
		    $notice = &get_message(array('msg'=>"操作成功！",'url'=>'?app='.$this->type.'&act=index','title'=>'Notice'));
		    $notice ->display();	 
		}

    }		
	

    function del()
    {  
	    if(!isset($_POST['jobs'])){$_POST['jobs']=0;}	
		$jobs = $_POST['jobs'];
        if($jobs ==='del')
		 {
		    if(!isset($_POST['checkdata'])){$_POST['checkdata']=array();}
             if(empty($_POST['checkdata']))
			 {
		    $notice = &get_message(array('msg'=>"请至少选择一个删除项目！",'url'=>'?app='.$this->type.'&act=index','title'=>'Notice'));
		    $notice ->display();				 
			 }
		    $checkdata = $_POST['checkdata'];		

			$str='';
			foreach($checkdata as $key => $value)
			{
			  $str.="id='".$value."'  or ";

		     if($value&&file_exists(ROOT_PATH . '/' . UPFILE_PATH . '/' . $this->type . '/' . $value. '/'))
		     {
		     del_file(ROOT_PATH . '/' . UPFILE_PATH . '/' . $this->type . '/' . $value. '/');
		     }				  		  
			}			
			$str = substr($str, 0,-3);
			$db = & get_db();			
			$db->query("DELETE FROM ".DB_PREFIX."content_".$this->table_id." WHERE "	.$str. " ");
		    $view = &get_view();
			foreach($checkdata as $key => $value)
			{
	        $view->delhtml($value,$this->type);			  		  
			}				
		
		    $notice = &get_message(array('msg'=>"删除成功！",'url'=>'?app='.$this->type.'&act=index','title'=>'Notice'));
		    $notice ->display();				 
	         
		}
		$cat= intval($_GET['cat']);	
		$id= intval($_GET['id']);

		   if($id&&file_exists(ROOT_PATH . '/' . UPFILE_PATH . '/' . $this->type . '/' . $id. '/'))
		   {
		     del_file(ROOT_PATH . '/' . UPFILE_PATH . '/' . $this->type . '/' . $id. '/');
		   }			
	
			
		$TB_new = &$this->_model('content');
		
		$TB_new->del($id,$this->table_id,$cat);

		$view = &get_view();
	    $view->delhtml($id,$this->type);						  
        $this->index();    
    }	
	
    function lcsort()
    {
		$id= intval($_GET['id']);
		$v= intval($_GET['v']);		
        unset($data);
		$data[sort_order] = $v;
		
	    $category = & $GLOBALS['SCup']->_get_category();		 		 		
		$category->editsort($id,$data);
		
		$category->write_cache($this->type);	
					      
		$this->cagrylist();   
    }	
		
    function delcatgy()
    {
		$id= intval($_GET['id']);		

		 $db = & get_db();
	     $rs=$db->get_one("SELECT count(*) AS num FROM ".DB_PREFIX."content_{$this->table_id} WHERE cat_id='$id' ");	
	     if($rs['num'])
		 {	
		 $notice = &get_message(array('msg'=>'本分类还有内容了,请先删除内容','url'=>'','title'=>'Notice'));
		 $notice ->display();			
	     }

	    $category = & $GLOBALS['SCup']->_get_category();		 		 		
		$category->del($id);
		
		$category->write_cache($this->type);
		$pic_dir = $this->view_scup_dir."/contentshow_{$this->table_id}_{$id}.view.html";
		$pic_dir1 = $this->view_scup_dir."/content_{$this->table_id}_{$id}.view.html";
		if(!is_dir($pic_dir)&&file_exists($pic_dir))
		{
		    del_file($pic_dir);	
		}			
		if(!is_dir($pic_dir1)&&file_exists($pic_dir1))
		{
		    del_file($pic_dir1);	
		}			
			      
		$this->cagrylist();   
    }	

    function get_view_data()
    {
	    if(!isset($this->view_data))
		{
		$this->view_data =array();
		}
	   if ($this->view_data == null)
       {
	        $dirname = $this->view_scup_dir.'/content';		
		    $this->view_data = get_all_dirname($dirname);
	   }
	   
	   return $this->view_data;
	  	
    }

	function write_module_default_scup_html($catid=0,$viewname='content.view.html')
    {	
		
	    $view_scup_index = stripslashes(read_file($this->view_scup_dir.'/content/'.$viewname));	
     	write_file($this->view_scup_dir."/content_{$this->table_id}_{$catid}.view.html",$view_scup_index);
		
   	    if(!is_writable($this->view_scup_dir."/content_{$this->table_id}_{$catid}.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/content_{$this->table_id}_{$catid}.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }


    }
	function write_module_default_scupshow_html($catid=0,$viewshowname='contentshow.view.html')
    {	
		
	    $view_scup_show = stripslashes(read_file($this->view_scup_dir.'/content/'.$viewshowname));	
     	write_file($this->view_scup_dir."/contentshow_{$this->table_id}_{$catid}.view.html",$view_scup_show);
		
   	    if(!is_writable($this->view_scup_dir."/contentshow_{$this->table_id}_{$catid}.view.html"))
		{	
		 $notice = &get_message(array('msg'=>$this->view_scup_dir."/contentshow_{$this->table_id}_{$catid}.view.html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		 $notice ->display();		
	    }


    }
		
}





?>